source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-300.rds.xz")
summary(model)
SOM of size 10x10 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.401.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1099 185 1019 382 1040 936 579 280 69 10 1419 995 409 1363 1283 929
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
1069 936 454 649 1405 983 1461 1078 1068 806 759 380 322 447 1464 1379
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
1346 750 734 312 875 511 691 698 565 1304 1763 410 745 67 635 1033
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
1168 1082 1296 1264 1321 1203 1257 412 882 1463 1417 1516 1967 1215 1169 1304
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
1205 990 940 660 1167 472 1564 1101 1445 945 1400 889 1171 1070 1458 191
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
741 1336 680 968 1336 1918 367 1855 1016 701 479 319 276 722 1077 958
97 98 99 100
1655 1254 1024 499
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 10*10;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("tmax", "tmin", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
tmax tmin precip longitud latitud altitud
[1,] -0.7672456 -0.8348501 0.2915467 0.4941919 0.25107496 0.38990749
[2,] -0.1462880 -0.1957130 -0.2437649 -0.4028492 -0.09864909 -0.03794298
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud altitud latitud tmax tmin precip
0.9823016 0.9749554 0.9736865 0.9638116 0.9603890 0.9482694
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 4.00 1st Qu.:147.0 1st Qu.: 50.00 1st Qu.: 3.00
Median : 6.00 Median :195.0 Median : 94.00 Median : 11.00
Mean : 6.48 Mean :199.7 Mean : 95.01 Mean : 15.34
3rd Qu.: 9.00 3rd Qu.:256.0 3rd Qu.: 142.00 3rd Qu.: 22.00
Max. :12.00 Max. :403.0 Max. : 254.00 Max. :167.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.99 1st Qu.:-4.8500
Median :0.000000 Median : 0.0000 Median :40.96 Median :-2.4831
Mean :0.000324 Mean : 0.5021 Mean :40.53 Mean :-2.4032
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 0.4942
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 251.5
Mean : 415.0
3rd Qu.: 667.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11 Min. :-27.00 Min. : 66.0 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 60.00 1st Qu.: 81.0 1st Qu.:0
Median :10.000 Median :148 Median : 80.00 Median : 92.0 Median :0
Mean : 7.336 Mean :155 Mean : 84.93 Mean :101.4 Mean :0
3rd Qu.:11.000 3rd Qu.:176 3rd Qu.:107.00 3rd Qu.:111.8 3rd Qu.:0
Max. :12.000 Max. :350 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.15 1st Qu.: -8.411 1st Qu.: 27.0
Median : 0.0000 Median :42.44 Median : -5.472 Median : 98.0
Mean : 0.4462 Mean :41.49 Mean : -4.768 Mean : 178.7
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 3.166 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.511 Mean :217.2 Mean :150.5 Mean : 7.218 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:189.5 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :185.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03078 Mean :28.37 Mean :-16.05 Mean : 520.2
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:131.0 1st Qu.: 35.00 1st Qu.: 6.00
Median : 5.000 Median :168.0 Median : 70.00 Median : 15.00
Mean : 6.112 Mean :165.7 Mean : 68.86 Mean : 18.89
3rd Qu.:10.000 3rd Qu.:204.0 3rd Qu.: 103.00 3rd Qu.: 27.00
Max. :12.000 Max. :352.0 Max. : 219.00 Max. :167.00
nevada prof_nieve longitud latitud
Min. :0.00000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.00000 1st Qu.: 0.0000 1st Qu.:39.49 1st Qu.:-5.2892
Median :0.00000 Median : 0.0000 Median :41.29 Median :-2.6544
Mean :0.00045 Mean : 0.6968 Mean :40.83 Mean :-2.4886
3rd Qu.:0.00000 3rd Qu.: 0.0000 3rd Qu.:42.43 3rd Qu.: 0.5356
Max. :6.00000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 47.0
Median : 258.0
Mean : 435.3
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11 Min. :-27.00 Min. : 66.0 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 60.00 1st Qu.: 81.0 1st Qu.:0
Median :10.000 Median :148 Median : 80.00 Median : 92.0 Median :0
Mean : 7.336 Mean :155 Mean : 84.93 Mean :101.4 Mean :0
3rd Qu.:11.000 3rd Qu.:176 3rd Qu.:107.00 3rd Qu.:111.8 3rd Qu.:0
Max. :12.000 Max. :350 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.15 1st Qu.: -8.411 1st Qu.: 27.0
Median : 0.0000 Median :42.44 Median : -5.472 Median : 98.0
Mean : 0.4462 Mean :41.49 Mean : -4.768 Mean : 178.7
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 3.166 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.511 Mean :217.2 Mean :150.5 Mean : 7.218 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:189.5 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :185.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03078 Mean :28.37 Mean :-16.05 Mean : 520.2
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :187.0 Min. : 45.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:264.0 1st Qu.:138.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :286.0 Median :164.0 Median : 4.00 Median :0
Mean : 7.425 Mean :287.1 Mean :162.3 Mean : 6.19 Mean :0
3rd Qu.: 8.000 3rd Qu.:309.0 3rd Qu.:188.0 3rd Qu.:10.00 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :49.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.6992 1st Qu.: 43.0
Median : 0.00000 Median :40.38 Median :-2.3567 Median : 247.0
Mean : 0.00145 Mean :39.76 Mean :-2.1835 Mean : 362.9
3rd Qu.: 0.00000 3rd Qu.:41.52 3rd Qu.: 0.4942 3rd Qu.: 656.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1405.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:135.0 1st Qu.: 38.00 1st Qu.: 6.00
Median : 5.000 Median :170.0 Median : 71.00 Median :14.00
Mean : 6.092 Mean :169.5 Mean : 71.42 Mean :18.18
3rd Qu.:10.000 3rd Qu.:205.0 3rd Qu.: 104.00 3rd Qu.:26.00
Max. :12.000 Max. :352.0 Max. : 219.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.48 1st Qu.:-5.4981
Median :0.000000 Median : 0.00000 Median :41.19 Median :-2.7331
Mean :0.000472 Mean : 0.06769 Mean :40.78 Mean :-2.5934
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.38 3rd Qu.: 0.4914
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 247.0
Mean : 354.7
3rd Qu.: 628.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11 Min. :-27.00 Min. : 66.0 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 60.00 1st Qu.: 81.0 1st Qu.:0
Median :10.000 Median :148 Median : 80.00 Median : 92.0 Median :0
Mean : 7.336 Mean :155 Mean : 84.93 Mean :101.4 Mean :0
3rd Qu.:11.000 3rd Qu.:176 3rd Qu.:107.00 3rd Qu.:111.8 3rd Qu.:0
Max. :12.000 Max. :350 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.15 1st Qu.: -8.411 1st Qu.: 27.0
Median : 0.0000 Median :42.44 Median : -5.472 Median : 98.0
Mean : 0.4462 Mean :41.49 Mean : -4.768 Mean : 178.7
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 3.166 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.511 Mean :217.2 Mean :150.5 Mean : 7.218 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:189.5 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :185.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03078 Mean :28.37 Mean :-16.05 Mean : 520.2
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :187.0 Min. : 45.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:264.0 1st Qu.:138.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :286.0 Median :164.0 Median : 4.00 Median :0
Mean : 7.425 Mean :287.1 Mean :162.3 Mean : 6.19 Mean :0
3rd Qu.: 8.000 3rd Qu.:309.0 3rd Qu.:188.0 3rd Qu.:10.00 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :49.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.6992 1st Qu.: 43.0
Median : 0.00000 Median :40.38 Median :-2.3567 Median : 247.0
Mean : 0.00145 Mean :39.76 Mean :-2.1835 Mean : 362.9
3rd Qu.: 0.00000 3rd Qu.:41.52 3rd Qu.: 0.4942 3rd Qu.: 656.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1405.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 31.00 1st Qu.: -31.00 1st Qu.: 16.00
Median : 7.000 Median : 76.00 Median : 9.00 Median : 29.00
Mean : 6.526 Mean : 85.96 Mean : 15.54 Mean : 33.68
3rd Qu.:10.000 3rd Qu.:139.00 3rd Qu.: 63.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :167.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1055
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.29 Median : 0.8842 Median :2143
Mean :0 Mean : 13.77 Mean :41.92 Mean :-0.3115 Mean :2111
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 3.000 1st Qu.:135.0 1st Qu.: 38.00 1st Qu.: 6.00
Median : 5.000 Median :170.0 Median : 71.00 Median :14.00
Mean : 6.092 Mean :169.5 Mean : 71.42 Mean :18.18
3rd Qu.:10.000 3rd Qu.:205.0 3rd Qu.: 104.00 3rd Qu.:26.00
Max. :12.000 Max. :352.0 Max. : 219.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.48 1st Qu.:-5.4981
Median :0.000000 Median : 0.00000 Median :41.19 Median :-2.7331
Mean :0.000472 Mean : 0.06769 Mean :40.78 Mean :-2.5934
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.38 3rd Qu.: 0.4914
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 247.0
Mean : 354.7
3rd Qu.: 628.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11 Min. :-27.00 Min. : 66.0 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 60.00 1st Qu.: 81.0 1st Qu.:0
Median :10.000 Median :148 Median : 80.00 Median : 92.0 Median :0
Mean : 7.342 Mean :155 Mean : 84.93 Mean :100.2 Mean :0
3rd Qu.:11.000 3rd Qu.:176 3rd Qu.:107.00 3rd Qu.:111.0 3rd Qu.:0
Max. :12.000 Max. :331 Max. :223.00 Max. :250.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.15 1st Qu.: -8.411 1st Qu.: 27.0
Median : 0.0000 Median :42.44 Median : -5.346 Median : 98.0
Mean : 0.4489 Mean :41.50 Mean : -4.749 Mean : 175.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 3.166 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 37.0 Min. :-11.0 Min. :252.0 Min. :0
1st Qu.: 2.25 1st Qu.:110.5 1st Qu.: 49.5 1st Qu.:279.2 1st Qu.:0
Median : 5.50 Median :127.0 Median : 78.5 Median :302.0 Median :0
Mean : 6.20 Mean :151.9 Mean : 86.1 Mean :309.6 Mean :0
3rd Qu.:10.25 3rd Qu.:172.5 3rd Qu.:114.8 3rd Qu.:317.2 3rd Qu.:0
Max. :12.00 Max. :350.0 Max. :204.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.:0 1st Qu.:38.05 1st Qu.: -8.649 1st Qu.: 37.02
Median :0 Median :41.95 Median : -8.517 Median : 262.00
Mean :0 Mean :38.95 Mean : -7.893 Mean : 640.81
3rd Qu.:0 3rd Qu.:42.43 3rd Qu.: -3.781 3rd Qu.: 571.75
Max. :0 Max. :43.36 Max. : -1.033 Max. :2371.00
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.511 Mean :217.2 Mean :150.5 Mean : 7.218 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:189.5 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :185.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03078 Mean :28.37 Mean :-16.05 Mean : 520.2
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :187.0 Min. : 45.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:264.0 1st Qu.:138.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :286.0 Median :164.0 Median : 4.00 Median :0
Mean : 7.425 Mean :287.1 Mean :162.3 Mean : 6.19 Mean :0
3rd Qu.: 8.000 3rd Qu.:309.0 3rd Qu.:188.0 3rd Qu.:10.00 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :49.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.6992 1st Qu.: 43.0
Median : 0.00000 Median :40.38 Median :-2.3567 Median : 247.0
Mean : 0.00145 Mean :39.76 Mean :-2.1835 Mean : 362.9
3rd Qu.: 0.00000 3rd Qu.:41.52 3rd Qu.: 0.4942 3rd Qu.: 656.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1405.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 31.00 1st Qu.: -31.00 1st Qu.: 16.00
Median : 7.000 Median : 76.00 Median : 9.00 Median : 29.00
Mean : 6.526 Mean : 85.96 Mean : 15.54 Mean : 33.68
3rd Qu.:10.000 3rd Qu.:139.00 3rd Qu.: 63.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :167.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1055
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.29 Median : 0.8842 Median :2143
Mean :0 Mean : 13.77 Mean :41.92 Mean :-0.3115 Mean :2111
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. : 8 Min. :-62.00 Min. : 0.00
1st Qu.: 3.00 1st Qu.:152 1st Qu.: 59.00 1st Qu.: 6.00
Median : 5.00 Median :180 Median : 87.00 Median :16.00
Mean : 6.14 Mean :182 Mean : 88.36 Mean :20.45
3rd Qu.:10.00 3rd Qu.:214 3rd Qu.:119.00 3rd Qu.:31.00
Max. :12.00 Max. :352 Max. :219.00 Max. :88.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.37 1st Qu.:-5.6417
Median :0.000000 Median : 0.0000 Median :41.43 Median :-1.7869
Mean :0.000308 Mean : 0.0388 Mean :40.72 Mean :-2.2380
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.85 3rd Qu.: 0.8031
Max. :4.000000 Max. :59.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 24.0
Median : 71.0
Mean : 156.6
3rd Qu.: 247.0
Max. :1668.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11 Min. :-27.00 Min. : 66.0 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 60.00 1st Qu.: 81.0 1st Qu.:0
Median :10.000 Median :148 Median : 80.00 Median : 92.0 Median :0
Mean : 7.342 Mean :155 Mean : 84.93 Mean :100.2 Mean :0
3rd Qu.:11.000 3rd Qu.:176 3rd Qu.:107.00 3rd Qu.:111.0 3rd Qu.:0
Max. :12.000 Max. :331 Max. :223.00 Max. :250.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.15 1st Qu.: -8.411 1st Qu.: 27.0
Median : 0.0000 Median :42.44 Median : -5.346 Median : 98.0
Mean : 0.4489 Mean :41.50 Mean : -4.749 Mean : 175.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 3.166 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 37.0 Min. :-11.0 Min. :252.0 Min. :0
1st Qu.: 2.25 1st Qu.:110.5 1st Qu.: 49.5 1st Qu.:279.2 1st Qu.:0
Median : 5.50 Median :127.0 Median : 78.5 Median :302.0 Median :0
Mean : 6.20 Mean :151.9 Mean : 86.1 Mean :309.6 Mean :0
3rd Qu.:10.25 3rd Qu.:172.5 3rd Qu.:114.8 3rd Qu.:317.2 3rd Qu.:0
Max. :12.00 Max. :350.0 Max. :204.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.:0 1st Qu.:38.05 1st Qu.: -8.649 1st Qu.: 37.02
Median :0 Median :41.95 Median : -8.517 Median : 262.00
Mean :0 Mean :38.95 Mean : -7.893 Mean : 640.81
3rd Qu.:0 3rd Qu.:42.43 3rd Qu.: -3.781 3rd Qu.: 571.75
Max. :0 Max. :43.36 Max. : -1.033 Max. :2371.00
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.0 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.0 Median :129.0 Median : 50.00 Median : 3.00 Median :0
Mean : 6.6 Mean :138.1 Mean : 60.62 Mean : 11.01 Mean :0
3rd Qu.:10.0 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.0 Max. :253.0 Max. :159.00 Max. :185.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1757 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :187.0 Min. : 45.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:264.0 1st Qu.:138.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :286.0 Median :164.0 Median : 4.00 Median :0
Mean : 7.425 Mean :287.1 Mean :162.3 Mean : 6.19 Mean :0
3rd Qu.: 8.000 3rd Qu.:309.0 3rd Qu.:188.0 3rd Qu.:10.00 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :49.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.6992 1st Qu.: 43.0
Median : 0.00000 Median :40.38 Median :-2.3567 Median : 247.0
Mean : 0.00145 Mean :39.76 Mean :-2.1835 Mean : 362.9
3rd Qu.: 0.00000 3rd Qu.:41.52 3rd Qu.: 0.4942 3rd Qu.: 656.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1405.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:107.0 1st Qu.: 11.00 1st Qu.: 6.00
Median : 4.000 Median :140.0 Median : 37.00 Median :12.00
Mean : 5.999 Mean :145.6 Mean : 38.86 Mean :13.82
3rd Qu.:10.000 3rd Qu.:185.0 3rd Qu.: 68.00 3rd Qu.:20.00
Max. :12.000 Max. :279.0 Max. : 145.00 Max. :62.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :37.13 Min. :-8.624
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.35 1st Qu.:-4.535
Median :0.000000 Median : 0.0000 Median :40.95 Median :-3.678
Mean :0.000789 Mean : 0.1233 Mean :40.89 Mean :-3.277
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.77 3rd Qu.:-1.885
Max. :6.000000 Max. :75.0000 Max. :43.57 Max. : 2.482
altitud
Min. : 4.0
1st Qu.: 609.0
Median : 704.0
Mean : 735.5
3rd Qu.: 900.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 31.00 1st Qu.: -31.00 1st Qu.: 16.00
Median : 7.000 Median : 76.00 Median : 9.00 Median : 29.00
Mean : 6.526 Mean : 85.96 Mean : 15.54 Mean : 33.68
3rd Qu.:10.000 3rd Qu.:139.00 3rd Qu.: 63.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :167.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1055
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.29 Median : 0.8842 Median :2143
Mean :0 Mean : 13.77 Mean :41.92 Mean :-0.3115 Mean :2111
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.492 Mean :233.9 Mean :169.3 Mean : 6.421 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :115.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003514 Mean :28.38 Mean :-15.96 Mean :131.7
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 8.0 Min. :-62.00 Min. : 0.000
1st Qu.: 2.000 1st Qu.:145.0 1st Qu.: 44.00 1st Qu.: 3.000
Median : 4.000 Median :171.0 Median : 70.00 Median : 8.000
Mean : 5.689 Mean :171.7 Mean : 71.31 Mean : 9.466
3rd Qu.:11.000 3rd Qu.:200.0 3rd Qu.: 98.00 3rd Qu.:14.000
Max. :12.000 Max. :300.0 Max. :174.00 Max. :44.000
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :36.83 Min. :-5.8728
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.48 1st Qu.: 0.3264
Median :0.000000 Median : 0.00000 Median :41.15 Median : 0.6350
Mean :0.000755 Mean : 0.04247 Mean :40.45 Mean : 0.8055
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.65 3rd Qu.: 1.9756
Max. :4.000000 Max. :59.00000 Max. :43.56 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 25.0
Median : 71.0
Mean :144.4
3rd Qu.:196.0
Max. :916.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 11 Min. :-27.00 Min. : 66.0 Min. :0
1st Qu.: 3.000 1st Qu.:126 1st Qu.: 60.00 1st Qu.: 81.0 1st Qu.:0
Median :10.000 Median :148 Median : 80.00 Median : 92.0 Median :0
Mean : 7.342 Mean :155 Mean : 84.93 Mean :100.2 Mean :0
3rd Qu.:11.000 3rd Qu.:176 3rd Qu.:107.00 3rd Qu.:111.0 3rd Qu.:0
Max. :12.000 Max. :331 Max. :223.00 Max. :250.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:41.15 1st Qu.: -8.411 1st Qu.: 27.0
Median : 0.0000 Median :42.44 Median : -5.346 Median : 98.0
Mean : 0.4489 Mean :41.50 Mean : -4.749 Mean : 175.9
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 261.0
Max. :607.0000 Max. :43.57 Max. : 3.166 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 42.0 Min. :-44.00 Min. :15.00 Min. :0
1st Qu.: 4.000 1st Qu.:143.0 1st Qu.: 61.00 1st Qu.:33.00 1st Qu.:0
Median : 7.000 Median :184.0 Median : 92.00 Median :43.00 Median :0
Mean : 7.003 Mean :182.6 Mean : 94.35 Mean :44.34 Mean :0
3rd Qu.:10.000 3rd Qu.:221.0 3rd Qu.:130.00 3rd Qu.:54.00 3rd Qu.:0
Max. :12.000 Max. :352.0 Max. :219.00 Max. :88.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :37.18 Min. :-8.649 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:41.48 1st Qu.:-3.799 1st Qu.: 44.0
Median : 0.00000 Median :42.26 Median :-1.229 Median : 176.0
Mean : 0.04258 Mean :42.17 Mean :-1.232 Mean : 296.8
3rd Qu.: 0.00000 3rd Qu.:43.31 3rd Qu.: 1.827 3rd Qu.: 445.0
Max. :35.00000 Max. :43.57 Max. : 4.216 Max. :1668.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 82.0 Min. :-17.0 Min. : 0.0 Min. :0
1st Qu.: 3.000 1st Qu.:162.0 1st Qu.: 77.0 1st Qu.: 8.0 1st Qu.:0
Median : 5.000 Median :189.0 Median :102.0 Median :17.0 Median :0
Mean : 6.173 Mean :192.4 Mean :102.9 Mean :19.8 Mean :0
3rd Qu.:10.000 3rd Qu.:221.0 3rd Qu.:129.0 3rd Qu.:29.0 3rd Qu.:0
Max. :12.000 Max. :340.0 Max. :213.0 Max. :68.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.649 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:36.85 1st Qu.:-6.949 1st Qu.: 22.00
Median : 0.00000 Median :42.33 Median :-5.879 Median : 58.00
Mean : 0.03311 Mean :40.26 Mean :-5.882 Mean : 98.91
3rd Qu.: 0.00000 3rd Qu.:43.36 3rd Qu.:-4.846 3rd Qu.:127.00
Max. :36.00000 Max. :43.57 Max. :-1.008 Max. :582.00
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 37.0 Min. :-11.0 Min. :252.0 Min. :0
1st Qu.: 2.25 1st Qu.:110.5 1st Qu.: 49.5 1st Qu.:279.2 1st Qu.:0
Median : 5.50 Median :127.0 Median : 78.5 Median :302.0 Median :0
Mean : 6.20 Mean :151.9 Mean : 86.1 Mean :309.6 Mean :0
3rd Qu.:10.25 3rd Qu.:172.5 3rd Qu.:114.8 3rd Qu.:317.2 3rd Qu.:0
Max. :12.00 Max. :350.0 Max. :204.0 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :28.31 Min. :-16.499 Min. : 4.00
1st Qu.:0 1st Qu.:38.05 1st Qu.: -8.649 1st Qu.: 37.02
Median :0 Median :41.95 Median : -8.517 Median : 262.00
Mean :0 Mean :38.95 Mean : -7.893 Mean : 640.81
3rd Qu.:0 3rd Qu.:42.43 3rd Qu.: -3.781 3rd Qu.: 571.75
Max. :0 Max. :43.36 Max. : -1.033 Max. :2371.00
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.0 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.0 Median :129.0 Median : 50.00 Median : 3.00 Median :0
Mean : 6.6 Mean :138.1 Mean : 60.62 Mean : 11.01 Mean :0
3rd Qu.:10.0 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.0 Max. :253.0 Max. :159.00 Max. :185.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1757 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :187.0 Min. : 45.0 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:264.0 1st Qu.:138.0 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :286.0 Median :164.0 Median : 4.00 Median :0
Mean : 7.425 Mean :287.1 Mean :162.3 Mean : 6.19 Mean :0
3rd Qu.: 8.000 3rd Qu.:309.0 3rd Qu.:188.0 3rd Qu.:10.00 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :49.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-7.8603 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.98 1st Qu.:-4.6992 1st Qu.: 43.0
Median : 0.00000 Median :40.38 Median :-2.3567 Median : 247.0
Mean : 0.00145 Mean :39.76 Mean :-2.1835 Mean : 362.9
3rd Qu.: 0.00000 3rd Qu.:41.52 3rd Qu.: 0.4942 3rd Qu.: 656.0
Max. :35.00000 Max. :43.36 Max. : 4.2156 Max. :1405.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4.0 Min. :-110.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:107.0 1st Qu.: 11.00 1st Qu.: 6.00
Median : 4.000 Median :140.0 Median : 37.00 Median :12.00
Mean : 5.999 Mean :145.6 Mean : 38.86 Mean :13.82
3rd Qu.:10.000 3rd Qu.:185.0 3rd Qu.: 68.00 3rd Qu.:20.00
Max. :12.000 Max. :279.0 Max. : 145.00 Max. :62.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :37.13 Min. :-8.624
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.35 1st Qu.:-4.535
Median :0.000000 Median : 0.0000 Median :40.95 Median :-3.678
Mean :0.000789 Mean : 0.1233 Mean :40.89 Mean :-3.277
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.77 3rd Qu.:-1.885
Max. :6.000000 Max. :75.0000 Max. :43.57 Max. : 2.482
altitud
Min. : 4.0
1st Qu.: 609.0
Median : 704.0
Mean : 735.5
3rd Qu.: 900.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 31.00 1st Qu.: -31.00 1st Qu.: 16.00
Median : 7.000 Median : 76.00 Median : 9.00 Median : 29.00
Mean : 6.526 Mean : 85.96 Mean : 15.54 Mean : 33.68
3rd Qu.:10.000 3rd Qu.:139.00 3rd Qu.: 63.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :167.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1055
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.29 Median : 0.8842 Median :2143
Mean :0 Mean : 13.77 Mean :41.92 Mean :-0.3115 Mean :2111
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.492 Mean :233.9 Mean :169.3 Mean : 6.421 Mean :0
3rd Qu.: 9.000 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :115.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003514 Mean :28.38 Mean :-15.96 Mean :131.7
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)